require("../../../utils/api.js");

var a = require("../../../utils/disapi.js"), t = getApp();

Page({
    data: {
        cashInfo: "",
        cashType: "wx",
        showLoding: !0,
        value: 0,
        than: !1,
        less: !0,
        lessMoney: 1,
        money_cash: 0,
        cash_money: "",
        comment: "",
        openid: ""
    },
    onLoad: function(o) {
        this.setData({
            openid: t.globalData.openid
        });
        var e = this;
        wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        }), a.get_dis_user_info({
            openid: this.data.openid
        }).then(function(a) {
            if (0 == a.errno) {
                var t = a.data;
                if (0 == t.code) {
                    var o = t.data;
                    console.log(o), e.setData({
                        money_cash: o.money
                    });
                }
            }
        }), a.get_dis_cash_comment().then(function(a) {
            console.log(a), 0 == a.errno && e.setData({
                comment: a.data
            });
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    navchange: function(a) {
        console.log(a);
        var t = this, o = a.currentTarget.dataset.type;
        t.setData({
            cashType: o,
            name: "",
            bankName: "",
            account: ""
        });
    },
    changeinfo: function(a) {
        console.log(a);
        var t = this, o = a.currentTarget.dataset.types, e = a.detail.value;
        "account" == o && t.setData({
            account: e
        }), "name" == o && t.setData({
            name: e
        }), "bankname" == o && t.setData({
            bankName: e
        });
    },
    allcash: function() {
        var a = this, t = a.data.money_cash;
        parseInt(t) < parseFloat(a.data.lessMoney) ? a.setData({
            cash: t,
            than: !1,
            less: !0,
            value: 0
        }) : a.setData({
            cash: t,
            than: !1,
            less: !1,
            value: t
        });
    },
    btn: function(t) {
        var o = this, e = o.data.value, n = o.data.cashType;
        if (console.log(e), "" == e) return !1;
        if ("wx" == n) {
            console.log(t);
            s = {
                money: parseFloat(e).toFixed(2),
                openid: this.data.openid,
                form_id: t.detail.formId,
                type: 1
            };
        } else if ("zfb" == n) {
            if (console.log(t), "" == o.data.account || void 0 == o.data.account) return wx.showToast({
                title: "请填写支付宝账号",
                icon: "none",
                duration: 2e3
            }), !1;
            if ("" == o.data.name || void 0 == o.data.name) return wx.showToast({
                title: "请填写真实姓名",
                icon: "none",
                duration: 2e3
            }), !1;
            s = {
                money: parseFloat(e).toFixed(2),
                openid: this.data.openid,
                form_id: t.detail.formId,
                type: 2,
                logo: o.data.account,
                value: o.data.name
            };
        } else if ("wy" == n) {
            if (console.log(t), "" == o.data.account || void 0 == o.data.account) return wx.showToast({
                title: "请填写银行卡账号",
                icon: "none",
                duration: 2e3
            }), !1;
            if ("" == o.data.name || void 0 == o.data.name) return wx.showToast({
                title: "请填写真实姓名",
                icon: "none",
                duration: 2e3
            }), !1;
            if ("" == o.data.bankName || void 0 == o.data.bankName) return wx.showToast({
                title: "请填写银行卡开户行名称",
                icon: "none",
                duration: 2e3
            }), !1;
            var s = {
                money: parseFloat(e).toFixed(2),
                openid: this.data.openid,
                type: 3,
                logo: o.data.account,
                value: o.data.name,
                address: o.data.bankName,
                form_id: t.detail.formId
            };
        }
        console.log(s), a.put_dis_cash(s).then(function(a) {
            if (console.log(a), 0 == a.errno) {
                var t = a.data;
                wx.showModal({
                    title: "提示",
                    content: t.msg,
                    showCancel: !1,
                    success: function(a) {
                        if (a.confirm) return o.onLoad({}), !1;
                    }
                });
            }
        });
    },
    money: function(a) {
        var t = this, o = a.detail.value;
        console.log(parseFloat(o)), parseFloat(o) > parseFloat(t.data.cashInfo.cash) ? t.setData({
            than: !0,
            less: !1
        }) : isNaN(parseFloat(o)) ? t.setData({
            less: !0,
            than: !1,
            cash: ""
        }) : "" == o ? t.setData({
            less: !0,
            than: !1,
            cash: ""
        }) : o < parseFloat(t.data.lessMoney) ? t.setData({
            less: !0,
            than: !1
        }) : (t.setData({
            than: !1,
            value: o,
            cash: o,
            less: !1
        }), console.log(t.data.value));
    }
});